<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAccessRolesRelationAccessMenusTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('access_roles_relation_access_menus', function (Blueprint $table) {
            $table->integer('role_id')->unsigned();                           // 管理者 id
            $table->integer('menu_id')->unsigned();                                 // 菜单 id
            $table->foreign('role_id')->references('id')->on('access_roles');   // 角色 id 外键索引
            $table->foreign('menu_id')->references('id')->on('access_menus');       // 菜单 id 外键索引
            $table->unique(['role_id', 'menu_id']);                           // 创建联合索引
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('access_roles_relation_access_menus');
    }
}
